<?php
/*--------------------------
  general information
----------------------------*/

//-- password --//
$cal_cfg['password'] = 'demo';

//-- document root --//
$cal_cfg['document_root'] = $_SERVER['DOCUMENT_ROOT'];

//-- time zone (from -12 to 12) --//
$cal_cfg['timezone'] = 0;

//-- is sunday the last day of the week ? (TRUE/FALSE) --//
$cal_cfg['sunday_endweek'] = false;

//-- months --//
$cal_cfg['month'] = array(
						'January',
						'February',
						'March',
						'April',
						'May',
						'June',
						'July',
						'August',
						'September',
						'October',
						'November',
						'December'
					);


/*----------------------
 popup's template
 ------------------------*/

// -- header -- //
$cal_cfg['popup']['header'] = <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<link rel="stylesheet" type="text/css" href="./style.css" />
		<title>Winged Calendar</title>
		<style type="text/css"><!--
		body {background-color:#000; color:#fff; margin:0; padding:1em}
		
		--></style>
	</head>
	<body>
EOT;

//-- footer --//
$cal_cfg['popup']['footer'] = '</body></html>';

//-- notices --//
$cal_cfg['popup']['notices'] = array (
							'access'  => 'Unauthorised access',
							'invalid' => 'Invalid input',
							'add'     => 'The event has been added.\nWould you like to reload the calendar?',
							'del'     => 'The event has been deleted.\nWould you like to reload the calendar?',
							'edit'    => 'The event has been edited.\nWould you like to reload the calendar?'
							);

//-- javascript stuff --//
$cal_cfg['popup']['js']['alert'] = <<<EOT
{ALERT}
<script type="text/javascript"><!--
	opener.alert("{ALERT}");
	window.close();
--></script>
EOT;

$cal_cfg['popup']['js']['confirm'] = <<<EOT
{CONFIRM}
<script type="text/javascript"><!--
	var confirm = opener.confirm("{CONFIRM}");
	if (confirm) {
		reloadCalendar();
		closing();
	} else {
		window.close();
	}
	function closing() {
		if (!opener.calendarIsLoaded) {
			setTimeout("closing()", 1000);
		} else {
			window.close();
		}
	}
	function reloadCalendar() {
		var rows = opener.document.getElementById("calendar").getElementsByTagName("tr");
		for (var i=0; i<rows.length; i++) {
			if (rows[i].className=="title") {
				var dates = rows[i].getElementsByTagName("td")[1].id.substring(1).split("-");
				opener.calendar(dates[0], dates[1]);
				break;
			}
		}
	}
--></script>
EOT;

$cal_cfg['popup']['js']['form_script'] = <<<EOT
<script type="text/javascript"><!--
	document.getElementsByTagName("a")[0].onclick = function() {
		opener.open(this.href, "_blank");
		return false;
	}
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].name=="del") {
			inputs[i].onclick = function() {
				return confirm("Are you sure to delete this event?");
			}
			break;
		}
	}
--></script>
EOT;


/*----------------
  templates
------------------*/

//-- calendar body --//
$cal_cfg['template']['body'] = <<<EOT
<table class="calendarDetail" cellspacing="0" cellpadding="0">
	<tr class="title">
		<td id="l{LAST_MON}-{LAST_YEAR}"><a href="#" title="{LAST_MON}-{LAST_YEAR}">&laquo;</a></td>
		<td id="c{MON}-{YEAR}" colspan="5"><a href="#" title="Reload this month">{MONTH} {YEAR}</a></td>
		<td id="n{NEXT_MON}-{NEXT_YEAR}"><a href="#" title="{NEXT_MON}-{NEXT_YEAR}">&raquo;</a></td>
	</tr>
	<tr class="title1">
		<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
	</tr>
	<!-- BEGIN -->
	<tr class="week">
		<td id="{ID_0}" class="{WHICH_0}"><a href="#">{DAY_0}</a>{EVENT_0}</td>
		<td id="{ID_1}" class="{WHICH_1}"><a href="#">{DAY_1}</a>{EVENT_1}</td>
		<td id="{ID_2}" class="{WHICH_2}"><a href="#">{DAY_2}</a>{EVENT_2}</td>
		<td id="{ID_3}" class="{WHICH_3}"><a href="#">{DAY_3}</a>{EVENT_3}</td>
		<td id="{ID_4}" class="{WHICH_4}"><a href="#">{DAY_4}</a>{EVENT_4}</td>
		<td id="{ID_5}" class="{WHICH_5}"><a href="#">{DAY_5}</a>{EVENT_5}</td>
		<td id="{ID_6}" class="{WHICH_6}"><a href="#">{DAY_6}</a>{EVENT_6}</td>
	</tr>
	<!-- END -->
</table>
EOT;

//-- float event window --//
$cal_cfg['template']['event'] = <<<EOT
<br />
<ul class="calendarEvent" id="e{DAY}-{MONTH}-{YEAR}">
	<!-- BEGIN -->
	<li>
		<div class="date">{YEAR}-{MONTH}-{DAY}, {HR}:{MIN}</div>
		<div class="edit"><a href="#" onclick="edit('{ID}'); return false">[edit]</a></div>
		{MESSAGE}
	</li>
	<!-- END -->
</ul>
EOT;

//-- add/edit event form --//
$cal_cfg['template']['form'] = <<<EOT
<div id="calendarForm">
	<div class="title">Add / Edit an event</div>
	<form action="./calendar_handle.php" method="post">
		<div>
		<input type="hidden" name="do" value="{DO}" />
		<input type="hidden" name="id" value="{ID}" />
		<div style="float:left; width:6em">Date:</div>
		<select name="day">
			{DAY}
		</select> -
		<select name="month">
			<option value="0">Every month</option><option>-----------</option>
			{MONTH}
		</select> -
		<select name="year">
			<option value="0">Every year</option><option>-----------</option>
			{YEAR}
		</select><br />
		<div style="float:left; width:6em">Time:</div>
		<select name="hr">
			{HOUR}
		</select> :
		<select name="min">
			{MINUTE}
		</select><br />
		<div style="float:left; width:6em">Message:</div><textarea name="message" rows="5" cols="40" style="width:30em">{MESSAGE}</textarea><br />
		<div style="float:left; width:6em">Password:</div><input type="password" name="pass" style="width:30em" /><br />
		<input type="{ADD}" name="add" value=" Add " />
		<input type="{EDIT}" name="edit" value=" Edit " />
		<input type="{EDIT}" name="del" value="Delete" />
		</div>
	</form>
	<div class="credit">Calendar by <a href="http://winged.info">winged.info</a></div>
</div>
EOT;

//-- essential javascript stuff --//
$cal_cfg['template']['js'] = <<<EOT
<script type="text/javascript"><!--
	var request;
	var calendarIsLoaded;
	function edit(id) {
		var url = "{HTPATH}/calendar_handle.php?edit=" + id;
		window.open(url, "Calendar", "width=500, height=300, scrollbars=1, resizable=1");
	}
	function calendar(month, year) {
		request = false;
		calendarIsLoaded = false;
		if (window.XMLHttpRequest) {
			try {
				request = new XMLHttpRequest();
			} catch (e) {
				request = false;
			}
		} else if (window.ActiveXObject) {
			try {
				request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					request = new ActiveXOjbject("Microsoft.XMLHTTP");
				} catch (e) {
					request = false;
				}
			}
		}
		if (request) {
			document.getElementById("calendar").innerHTML = "Loading...";
			request.onreadystatechange = handleResponse;
			request.open("GET", "{HTPATH}/calendar_handle.php?date=" + month + "-" + year, true);
			request.send("");
		} else {
			alert("Tough luck. No AJAX supported.");
		}
	}
	function handleResponse() {
		if (request.readyState==4) {
			if (request.status==200) {
				calendarIsLoaded = true;
				document.getElementById("calendar").innerHTML = request.responseText;
				addListeners();
			}
		}
	}
	function addListeners() {
		var isIE = navigator.userAgent.indexOf("MSIE 6")>-1 || navigator.userAgent.indexOf("MSIE 5")>-1;
		var rows = document.getElementById("calendar").getElementsByTagName("tr");
		for (var i=0; i<rows.length; i++) {
			if (rows[i].className=="title") {
				var cols = rows[i].getElementsByTagName("td");
				for (var j=0; j<cols.length; j++) {
					cols[j].getElementsByTagName("a")[0].onclick = function() {
						var dates = this.parentNode.id.substring(1).split("-");
						calendar(dates[0], dates[1]);
						return false;
					}
				}		
			} else if (rows[i].className=="week") {
				var cols = rows[i].getElementsByTagName("td");
				for (var j=0; j<cols.length; j++) {
					cols[j].getElementsByTagName("a")[0].onclick = function() {
						var url = "{HTPATH}/calendar_handle.php?add=" + this.parentNode.id.substring(1);
						window.open(url, "Calendar", "width=500, height=300, scrollbars=1, resizable=1");
						return false;
					}
					var event = document.getElementById("e" + cols[j].id.substring(1));
					if (isIE && event!=null) {
						cols[j].onmouseover = function() {
							document.getElementById("e" + this.id.substring(1)).style.display = "block";
						}
						cols[j].onmouseout = function() {
							document.getElementById("e" + this.id.substring(1)).style.display = "none";
						}
						event.onmouseover = function() {
							document.getElementById(this.id).style.display = "block";
						}
						event.onmouseout = function() {
							document.getElementById(this.id).style.display = "none";
						}
					}
				}
			}
		}
	}
	window.onload = addListeners;
--></script>
EOT;
?>
